<?php
/**
 * Created by PhpStorm.
 * User: 孙克强
 * Date: 2018/1/22
 * Time: 15:58
 */
class Role_model extends CI_Model{
    /**
     * User_model constructor.
     * 构造函数，加载数据库配置文件
     */
    public function __construct() {
        $this->load->database();
    }

    /**
     * 查询全部角色
     * @return mixed
     */
    public function getAll(){
        $query = $this->db->get('role');
        return $query->result_array();
    }

    /**
     * 添加角色
     * @param $data
     */
    public function addRole($data){
        $this->db->insert('role',$data);
    }

    /**
     * 删除角色
     * @param $id
     */
    public function deleteRole($id){
        $this->db->delete('role',array('role_id' => $id));
    }

    /**
     * 更新角色
     * @param $data
     */
    public function updateRole($data){
        $this->db->update('role',$data,array('role_id'=>$data['role_id']));
    }

    /**
     * 按id查询角色
     * @param $id
     * @return mixed
     */
    public function getRoleById($id){
        $query = $this->db->get_where('role',array('role_id' => $id));
        return $query->row_array();
    }

    /**
     * 模糊查询
     * @param $role_search
     * @return mixed
     */
    public function getSearch($role_search){
        $this->db->like('role_name',$role_search,'both');
        $query = $this->db->get('role');
        return $query->result_array();
    }
}